﻿<?php

$_shipmentType = $_POST['_shipmentType'];
$_dateStart  = $_POST['_dateStart'];
$_dateArrive  = $_POST['_dateArrive'];
$_fromWhere  = $_POST['_fromWhere'];
$_toWhere  = $_POST['_toWhere'];
$_Rphone  = $_POST['_Rphone'];
$_Raddress  = $_POST['_Raddress'];
$_Rname  = $_POST['_Rname'];
$_Sphone  = $_POST['_Sphone'];
$_Saddress  = $_POST['_Saddress'];
$_Sname  = $_POST['_Sname'];

$link=mysql_connect("localhost", "root" ,"1123");
mysql_select_db("dd") or die("No database");

//插入顧客

//產生唯一貨物ID
do
{
	$randomNumber = rand() * rand() * rand();
	$randomNumber %= 1000000000000;
	if($randomNumber < 0 )
	{
		$randomNumber *= -1;
	}
	$result = mysql_db_query("dd", "select * from shipment where tracking_number = '$randomNumber';");
}
while(mysql_fetch_row($result));

echo '您的送貨單號：' . $randomNumber;

$query = "  Insert into customer values('$_Rphone' , '$_Rname' , '$_Raddress');";
mysql_query($query);
$query = "  Insert into customer values('$_Sphone' , '$_Sname' , '$_Saddress');";
mysql_query($query);

//插入貨物
$query = "Insert into shipment(
						tracking_number,
						type ,
						mailing_date ,
						specified_delivery_date ,
						start_warehouse,
						end_warehouse,
						sender_phone,
						addressee_phone)
					values(
						'$randomNumber',
						'$_shipmentType' ,
						date'$_dateStart' ,
						date'$_dateArrive' ,
						'$_fromWhere',
						'$_toWhere',
						'$_Rphone',
						'$_Sphone');";
					
mysql_query($query) or die("Error Message:".mysql_error());

mysql_close ($link);

?>